package com.moyuwanjia.ui;

import com.moyuwanjia.factory.BeanFactory;
import com.moyuwanjia.pojo.User;
import com.moyuwanjia.service.UserService;
import com.moyuwanjia.service.impl.UserServiceImpl;

/**
 * @author 摸鱼丸加~
 * @create 2022-04-19 11:26
 * 模拟表现层，用于调用业务层
 */
public class Client {
    public static void main(String[] args){
        // new创建对象的方式使得程序的独立性很差，所以要设法解耦
//        UserService service = new UserServiceImpl();
        // 这里解耦的方式是通过工厂模式解耦
        // 这里使用循环创建多个对象查看多例和单例对象
        for (int i = 0; i < 5; i++) {
            //多例对象
            UserService userService = (UserServiceImpl) BeanFactory.getCasesBean("userService");
            System.out.println(userService.saveUsers(new User()));
            System.out.println(userService);
        }
        System.out.println("--------------------");
        for (int i = 0; i < 5; i++) {
            //单例对象
            UserService userService = (UserServiceImpl) BeanFactory.getSingletonBean("userService");
            System.out.println(userService.saveUsers(new User()));
            System.out.println(userService);
        }

    }
}
